package com.example.springbook.dao;

import com.example.springbook.bean.Borrow;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BorrowDao {
    @Insert("insert into borrow_detail(id,bookid,bookname,userid,username,lendtime) values ((select max(id)+1 from borrow_detail bd),#{bookid},#{bookname},#{userid},#{username},#{lendtime})")
    void addBorrow(Borrow borrow);

    @Update("update borrow_detail set returntime=now() where id=#{id}")
    void updateBorrow(int id);

    @Delete("delete from borrow_detail where id=#{id}")
    void deleteBorrow(int id);

    @Select("select * from borrow_detail")
    List<Borrow> findAllBorrow();

    @Select("select * from borrow_detail where bookid=#{bookid}")
    List<Borrow> findBorrowByBook(int bookid);

    @Select("select * from borrow_detail where userid=#{userid} and returntime is null")
    List<Borrow> findBorrowByUser(int userid);
}
